package com.monolithiot.notifier.common.util;

import java.util.UUID;

/**
 * 2018/11/19 Create by 郭文梁
 * IdentityUtil
 * ID工具类
 *
 * @author 郭文梁
 * @date 2018/11/19
 */
public class IdentityUtil {
    private static final char[] NUMBER_DIST = "0123456789".toCharArray();

    /**
     * 随机UUID
     *
     * @return UUID as string
     */
    public static String randomUUID() {
        return UUID.randomUUID().toString();
    }

    /**
     * 生成随机UUID 只包含数字和字母 不带横杠 [-]
     *
     * @return UUID as string
     */
    public static String randomPrettyUUID() {
        return randomUUID().replaceAll("-", "");
    }

    /**
     * 随机数字字符串
     *
     * @param len 长度
     * @return 字符串
     */
    public static String randomNumberCode(int len) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < len; i++) {
            int index = (int) (Math.random() * NUMBER_DIST.length);
            sb.append(NUMBER_DIST[index]);
        }
        return sb.toString();
    }
}
